home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5529 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  57 lines

  1. Newsgroups: comp.lang.c++
  2. Path: wdl1.wdl.loral.com!lds081!news
  3. From: John Whitmire <whitmire@lds.loral.com>
  4. Subject: Re: random number in C++
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <31163A9B.44D0@lds.loral.com>
  7. Sender: news@lds.loral.com
  8. Content-Transfer-Encoding: 7bit
  9. Organization: Loral Data Systems
  10. References: <4eoh03$6jb@pacemaker.cts> <Pine.SUN.3.91.960201080729.14827F-100000@szechuan>
  11. Mime-Version: 1.0
  12. Date: Mon, 5 Feb 1996 17:12:59 GMT
  13. X-Mailer: Mozilla 2.0b5 (Win16; I)
  14.  
  15. Joseph Strout wrote:
  16. > On 31 Jan 1996, Brian A. Bucher wrote:
  17. > > Is there _ANY_ way to get a truly random number in a C++ program?
  18. > > rand and srand do not generate random numbers, they generate
  19. > > pseudo-random numbers, which is what I don't need.
  20. > There is NO way to get a truly random number in any software.  Computers
  21. > today are deterministic, and given the same starting conditions, any
  22. > particular algorithm will give you the same result again and again.
  23. > In principle, one could build a random number chip which seeded itself
  24. > via quantum fluctuations, environmental noise, etc., but as far as I know
  25. > nobody has done this.
  26. > So the best you can do in software is find a good pseudorandom number
  27. > generator.  rand() isn't one -- I remember once I was generating random
  28. > Turing machines, using only the last bit returned from rand() calls, and
  29. > they came out 010101010101....
  30. > random() in the g++ <math.h> library is better, but this isn't available
  31. > on all platforms.  I think "Numerical Recipes in C" discusses
  32. > pseudorandom number generators, so you could code your own if needed.
  33. > What most people do is just seed the random number generator with some
  34. > mostly-unpredictable value, such as the system time or the number of
  35. > cycles it takes the user to press a key.
  36. > ,------------------------------------------------------------------.
  37. > |    Joseph J. Strout           Department of Neuroscience, UCSD   |
  38. > |    jstrout@ucsd.edu           http://www-acs.ucsd.edu/~jstrout/  |
  39. > `------------------------------------------------------------------'
  40.  
  41. Check out the Algorithm Alley column in DDJ, Nov 94, titled "Truly Random 
  42. Numbers".  The author applies some cryptographic principles and some 
  43. external stimuli (your typing) to improve the randomness. Source code is 
  44. available from ftp://ftp.mv.com/pub/ddj. Look for file AAL1194.
  45.  
  46. -- 
  47. =====================================================
  48. John Whitmire (whitmire@lds.loral.com)
  49.